/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Controller;

import Settings.KeyMap;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
import org.json.simple.JSONObject;
import worker.TerMessageProcessor;

 /*
 * @Author sabbir
 */
public class RequestController {
	private Logger logger = null;
	
	public RequestController()
	{
		logger=Logger.getLogger(RequestController.class.getName());
	}
	
	public JSONObject control(HttpServletRequest request)
	{
		JSONObject jsonObj=new JSONObject();
		JSONObject obj=null;
		try
		{
			obj = TerMessageProcessor.processData(request);
			jsonObj.put(KeyMap.JsonKeys.RESULT.toString(), true);
			jsonObj.put(KeyMap.JsonKeys.MESSAGE.toString(), null);
			jsonObj.put(KeyMap.JsonKeys.VALUE.toString(),obj);
		}catch(Exception ex)
		{
			logger.error(ex.getMessage());
			jsonObj.put(KeyMap.JsonKeys.RESULT.toString(), false);
			jsonObj.put(KeyMap.JsonKeys.MESSAGE.toString(), ex.getMessage());
			jsonObj.put(KeyMap.JsonKeys.VALUE.toString(),null);
		}
		
		return jsonObj;
	}
}
